@layout("/common/_curd/_container.html"){

	<form data-url="${basePath}/${code}/save" method="post" class="form-horizontal" role="form">
        <input type="hidden" name="tb_notice.teacher_auth" id="_teacher_auth"/>
        <input type="hidden" name="tb_notice.student_auth" id="_student_auth"/>
        <input type="hidden" name="tb_notice.parent_auth" id="_parent_auth"/>
		<!-- 表单 -->
		@ var _table="tb_notice";
		@ var _col=[
		@			  {name:"标题", index:"title", type:"text",newline:true,length:8,required:"required maxlength='100'"},
		@			  {name:"通知内容", index:"content", type:"text",newline:true,length:8,required:"required maxlength='500'"}
		@		   ];
		@ include("/common/_curd/_add.html", {"col":_col, "table":_table}){}
        <div class="form-group" style="display:block">
            <label class="col-sm-1 control-label no-padding-right">  </label>
            <div class="col-sm-10">


                <!-- 配置grid row这个class不能省略，会出问题-->
                <div class="row">
                    <div class="col-sm-4">
                        <div class="col-sm-12">
                            <div class="widget-box widget-color-blue2">
                                <div class="widget-header">
                                    <h4 class="widget-title lighter smaller">老师</h4>
                                </div>

                                <div class="widget-body">
                                    <div class="widget-main padding-8">
                                        <ul id="zTree" class="ztree"></ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-4">
                        <div class="col-sm-12">
                            <div class="widget-box widget-color-blue2">
                                <div class="widget-header">
                                    <h4 class="widget-title lighter smaller">家长</h4>
                                </div>

                                <div class="widget-body">
                                    <div class="widget-main padding-8">
                                        <ul id="zTree2" class="ztree"></ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-4">
                        <div class="col-sm-12">
                            <div class="widget-box widget-color-blue2">
                                <div class="widget-header">
                                    <h4 class="widget-title lighter smaller">学生</h4>
                                </div>

                                <div class="widget-body">
                                    <div class="widget-main padding-8">
                                        <ul id="zTree3" class="ztree"></ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="clear"></div>
                </div>

            </div>
        </div>


		<!-- 按钮 -->
		@ include("/common/_curd/_btn.html", {btn_save:"新增", btn_close:"关闭"}) {}
	</form>
<script>
    $(document).ready(function(){
        initZtree("getNoticeStuTree","zTree3");
        initZtree("getNoticeParTree","zTree2");
        initZtree("getNoticeTree","zTree");
    });

    function saveBefore() {
        var zTree = $.fn.zTree.getZTreeObj("zTree");
        var zTree2 = $.fn.zTree.getZTreeObj("zTree2");
        var zTree3 = $.fn.zTree.getZTreeObj("zTree3");

        var tree = selectTeaNodes(zTree);
        var tree2 = selectNodes(zTree2);
        var tree3 = selectNodes(zTree3);

        $("#_teacher_auth").val(tree);
        $("#_parent_auth").val(tree2);
        $("#_student_auth").val(tree3);

        if (!tree && !tree2 && !tree3) {
            layer.msg("选项不能为空", {shift: 6});
            return false;
        }
        return true;
    }

    function selectTeaNodes(tree){
        var nodes = tree.getCheckedNodes();
        var ids = "";
        var names = "";
        for (var i=0, l=nodes.length; i<l; i++) {
        	//var obj = nodes[i].getCheckStatus();
        	//if(!obj.half)
            if (nodes[i].leaf){
                ids += "," + nodes[i].id;
        }
        ids = ids.substring(1);
        return ids;
    }

    function selectNodes(tree){
        var nodes = tree.getCheckedNodes();
        var ids = "";
        var names = "";
        for (var i=0, l=nodes.length; i<l; i++) {
            //忽略老师或学生的顶级节点
            if (nodes[i].id == 1002 || nodes[i].id == 1001){
                continue;
            }
            ids += "," + nodes[i].id;
        }
        ids = ids.substring(1);
        return ids;
    }


    var setting = {
        check: {
            enable: true,
            chkboxType: {"Y": "ps", "N": "ps"},
            chkStyle : "checkbox"
        },
        data: {
            simpleData: {
                enable: true
            }
        }
    };

    function initZtree(url,node) {

        $.post("${basePath}/authTag/"+url,function(data){
            if(data.code===0){
                $.fn.zTree.init($("#"+node), setting, data.data);
            }
            else{
                layer_alert("数据加载失败", "error");
            }
        }, "json");
    }

</script>

<!-- 引入所需js -->
<link rel="stylesheet" href="${basePath}/static/zTree/css/zTreeStyle/zTreeStyle.css" />
<script src="${basePath}/static/zTree/js/jquery.ztree.core.js" type="text/javascript" ></script>
<script src="${basePath}/static/zTree/js/jquery.ztree.excheck.js" type="text/javascript"></script>
@}
